import formulas from '@/pages/Drag/sub-components/previewModal/formulas';
import {message} from 'antd';
import parseFormulas from './parseFormulas';

function checkFormValidator(validators:any[],formData:any[]){
  for(let i=0;i<validators.length;i++) {
    const item = validators[i];

    const {formula,remind}:any = item;
    const formulasKeys = Object.keys(formulas);
    const fkey = formula.split("(")[0];
    const key = formulasKeys.find(v => v===fkey);

    const args = parseFormulas(formula,formData);

    // console.log({args,key})
    
    if (key) {
      let res = formulas[key](...args);
      if(!res) {
        message.warning(remind);
        return false;
        break;
      }
    }
  }
  return true;
}

export default checkFormValidator;